﻿using System;
using System.Linq;

namespace ReadNumbersInRange
{
    class ReadNumbersInRange
    {
        static int ReadNumber(int start, int end)
        {
            Console.Write("Enter a integer number: ");
            int number = Int32.Parse(Console.ReadLine());
                
            if (number < start || number > end)
            {
                throw new ArgumentOutOfRangeException();
            }
            return number;      
        }
        
        static void Main()
        {
            /* 2. Write a method ReadNumber(int start, int end) that enters an integer number in given range [start…end]. 
             *    If an invalid number or non-number text is entered, the method should throw an exception. 
             *    Using this method write a program that enters 10 numbers:
             *    a1, a2, … a10, such that 1 < a1 < … < a10 < 100
             */
 
            try
            {
                int start = 1, end = 100;
                for (int i = 0; i < 10; i++)
                {
                    start = ReadNumber(start, end);
                }
            }
            catch (FormatException)
            {
                Console.WriteLine("Invalid number.");
            }
            catch (ArgumentOutOfRangeException)
            {
                Console.WriteLine("Invalid number - out of range.");
            }
        }
    }
}
